package tgc.edu.ljc.service;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import tgc.edu.ljc.custom.CommonService;
import tgc.edu.ljc.entity.DataSum;
import tgc.edu.ljc.repository.DataSumRepository;

@Service
public class DataSumService extends CommonService<DataSum, Integer> {
	@Autowired
	private DataSumRepository dataSumDAO;
	
	public List<DataSum> findFileNatures() {
		Specification<DataSum> spec=new Specification<DataSum>() {
			private static final long serialVersionUID = 7221381397165778321L;

			@Override
			public Predicate toPredicate(Root<DataSum> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				return cb.equal(root.get("parent").get("code"), "DICT_FILE_DOCUMENTS");
			}
		};
		return dataSumDAO.findAll(spec);
	}

	public List<DataSum> findFileTypes(){
		Specification<DataSum> spec=new Specification<DataSum>() {

			private static final long serialVersionUID = 1L;

			@Override
			public Predicate toPredicate(Root<DataSum> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				return cb.equal(root.get("parent").get("code"), "DICT_FILE_TYPE");
			}
		};
		return dataSumDAO.findAll(spec);
	}
}
